package com.payment.ktb.activity.main4;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.android.volley.VolleyError;
import com.payment.ktb.Interface.HttpCallbackListener;
import com.payment.ktb.R;
import com.payment.ktb.activity.BaseActivity;
import com.payment.ktb.activity.MainActivity;
import com.payment.ktb.constants.ConstantsUser;
import com.payment.ktb.constants.HttpActions;
import com.payment.ktb.constants.HttpUrls;
import com.payment.ktb.utils.AlertDialogUtils;
import com.payment.ktb.utils.HttpUtils;
import com.payment.ktb.utils.SharedPreferencesUtils;
import com.payment.ktb.utils.StringUtils;
import com.payment.ktb.utils.ToastUtils;

import java.util.HashMap;
import java.util.Map;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by admin on 2017/8/29.
 */

public class NicknameActivity extends BaseActivity {


    @BindView(R.id.et_nickname_nickname)
    EditText et_nickname_nickname;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_nickname);
        initRight("保存");
        initTitle("昵称");
        ButterKnife.bind(this);

    }


    @OnClick({R.id.rl_nickname_delete,R.id.tv_title_right})
    public void clickEvent(View view){

        switch (view.getId()){

            case R.id.rl_nickname_delete:
                et_nickname_nickname.setText("");
                break;

            case R.id.tv_title_right:
               if (TextUtils.isEmpty(et_nickname_nickname.getText().toString())) {
                   ToastUtils.showToast("昵称不能为空！");
               }else {
                   submit();
               }
                break;

        }

    }

    private void submit() {

        progressDialogUtils.showProgress();
        //构造传输参数
        Map<String, String> map = new HashMap<String,String>();
        final String userNick = et_nickname_nickname.getText().toString();
        map.put("picHeader", SharedPreferencesUtils.getString(SharedPreferencesUtils.getString(ConstantsUser.phone) + ConstantsUser.picHeader));
        map.put("userNick",userNick);

        //向服务器发送请求
        HttpUtils.HttpRequestByVollery(HttpUrls.URL, HttpActions.UserBaseDetailEditState, map, mQueue, new HttpCallbackListener() {
            @Override
            public void onFinish(String response) {
                progressDialogUtils.dismissProgress();
                ToastUtils.showToast("保存成功");
                SharedPreferencesUtils.putString(ConstantsUser.userNick,userNick);
                startActivity(MainActivity.class);
            }
            @Override
            public void onError(VolleyError volleyError) {
                progressDialogUtils.dismissProgress();
                AlertDialogUtils.showAlertDialog(mContext, volleyError.getMessage());
            }
        });
    }



}
